<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>CKEDITOR.xml</title>
	<link rel="stylesheet" type="text/css" href="../test.css" />
	<script type="text/javascript" src="../../ckeditor.js"></script>
	<script type="text/javascript" src="../../_source/core/loader.js"></script>
	<script type="text/javascript" src="../test.js"></script>
	<script type="text/javascript">
	//<![CDATA[

CKEDITOR.loader.load( 'core/xml' );

	//]]>
	</script>
	<script type="text/javascript">
	//<![CDATA[

CKEDITOR.test.addTestCase( (function()
{
	// Local reference to the "assert" object.
	var assert = CKEDITOR.test.assert;

	return {
		test_baseXml : function()
		{
			var xml = new CKEDITOR.xml( '<data />' );
			assert.isObject( xml.baseXml );
		},

		test_selectSingleNode1a : function()
		{
			var xml = new CKEDITOR.xml( '<data><item /></data>' );
			var node = xml.selectSingleNode( 'data/item' );
			assert.areEqual( 'item', node.nodeName );
		},

		test_selectSingleNode1b : function()
		{
			var xml = new CKEDITOR.xml( '<data><item /></data>' );
			var node = xml.selectSingleNode( 'item' );
			assert.isNull( node );
		},

		test_selectSingleNode2a : function()
		{
			var xml = new CKEDITOR.xml( '<data><item><subitem/></item></data>' );
			var contextNode = xml.selectSingleNode( 'data' );
			var node = xml.selectSingleNode( 'item/subitem', contextNode );
			assert.areEqual( 'subitem', node.nodeName );
		},

		test_selectSingleNode2b : function()
		{
			var xml = new CKEDITOR.xml( '<data><item><subitem/></item></data>' );
			var contextNode = xml.selectSingleNode( 'data' );
			var node = xml.selectSingleNode( 'subitem', contextNode );
			assert.isNull( node );
		},

		test_selectSingleNode3 : function()
		{
			var xml = new CKEDITOR.xml( '<data><item id="x1"/><item id="x2"/></data>' );
			var node = xml.selectSingleNode( '//item[@id="x2"]' );
			assert.areEqual( 'item', node.nodeName );
			assert.areEqual( 'x2', node.getAttribute( 'id' ) );
		},

		test_selectSingleNode4 : function()
		{
			// For may results, the first one must be returned.

			var xml = new CKEDITOR.xml( '<data><item id="x1"/><item id="x2"/></data>' );
			var node = xml.selectSingleNode( '//item' );
			assert.areEqual( 'item', node.nodeName );
			assert.areEqual( 'x1', node.getAttribute( 'id' ) );
		},

		test_selectNodes1 : function()
		{
			var xml = new CKEDITOR.xml( '<data><item /></data>' );
			var nodes = xml.selectNodes( 'data/item' );
			assert.areEqual( 1, nodes.length );
			assert.areEqual( 'item', nodes[0].nodeName );
		},

		test_selectNodes2a : function()
		{
			var xml = new CKEDITOR.xml( '<data><item id="x1"/><item id="x2"/><item id="x3"/></data>' );
			var nodes = xml.selectNodes( '//item' );
			assert.areEqual( 3, nodes.length );
			assert.areEqual( 'x1', nodes[0].getAttribute( 'id' ) );
			assert.areEqual( 'x2', nodes[1].getAttribute( 'id' ) );
			assert.areEqual( 'x3', nodes[2].getAttribute( 'id' ) );
		},

		test_selectNodes2b : function()
		{
			var xml = new CKEDITOR.xml( '<data><item id="x1"/><item id="x2"/><item id="x3"/></data>' );
			var nodes = xml.selectNodes( '//itemX' );
			assert.areEqual( 0, nodes.length );
		},

		test_selectNodes3a : function()
		{
			var xml = new CKEDITOR.xml( '<data><item id="x1"/><item id="x2"/><item id="x3"/></data>' );
			var contextNode = xml.selectSingleNode( 'data' );
			var nodes = xml.selectNodes( 'item', contextNode );
			assert.areEqual( 3, nodes.length );
			assert.areEqual( 'x1', nodes[0].getAttribute( 'id' ) );
			assert.areEqual( 'x2', nodes[1].getAttribute( 'id' ) );
			assert.areEqual( 'x3', nodes[2].getAttribute( 'id' ) );
		},

		test_selectNodes3b : function()
		{
			var xml = new CKEDITOR.xml( '<data><item id="x1"/><item id="x2"/><item id="x3"/></data>' );
			var contextNode = xml.selectSingleNode( 'data' );
			var nodes = xml.selectNodes( 'itemX', contextNode );
			assert.areEqual( 0, nodes.length );
		},

		test_getInnerXml1 : function()
		{
			var xml = new CKEDITOR.xml( '<data><item/></data>' );
			assert.areEqual( '<item/>', xml.getInnerXml( 'data' ) );
		},

		test_getInnerXml2 : function()
		{
			var xml = new CKEDITOR.xml( '<data><item id="x1"><subitem name="sub1"/></item></data>' );
			assert.areEqual( '<subitem name="sub1"/>', xml.getInnerXml( '//item' ) );
		},

		test_getInnerXml3 : function()
		{
			var xml = new CKEDITOR.xml( '<data><item id="x1"/></data>' );
			assert.isNull( xml.getInnerXml( '//itemX' ) );
		},

		name : document.title
	};
})() );

	//]]>
	</script>
</head>
<body>
</body>
</html>
